package cn.regexp.test;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

import java.util.*;
import java.util.stream.Collectors;

public class StreamPractice {
    @Data
    @AllArgsConstructor
    @ToString
    static class Language {
        private String planStudy;
        private String applyStudy;
    }

    public static void main(String[] args) {
        List<Language> languageList = Arrays.asList(
                new Language("JAVA", "Linux,Python"),
                new Language("MySQL", "C,C++"),
                new Language("Linux", "MySQL,Groovy"));

        Map<String, String> map1 = new HashMap<>();
        map1.put("Java", "20");
        map1.put("Python", "20");
        map1.put("JavaScript", "20");

        Map<String, String> map2 = new HashMap<>();
        map2.put("MySQL", "12");
        map2.put("Oracle", "12");

        Map<String, Map<String, String>> map = new HashMap<>();
        map.put("language", map1);
        map.put("database", map2);
        String languageStr = languageList.stream()
                .map(item -> Arrays.asList((item.getPlanStudy() + "," + item.getApplyStudy()).split(",")))
                .flatMap(Collection::stream)
                .distinct()
                .collect(Collectors.joining(","));

        Map<String, String> collectMap = map.values()
                .stream()
                .map(Map::entrySet)
                .flatMap(Set::stream)
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        System.out.println(collectMap);
    }
}
